var vehicleMonitor = {
    init : function(){
       mapTool.init();// 地图初始化
       this.trafficLayer=null;
       this.satelliteLayer=null;
       this.roadNetLayer =null;
       this.vehicleTimer=null;       // 订阅定时器
       this.terminalMap = new HashMap();
       this.vehicleMap = new HashMap();
       this.vehiclePosition(); 
       this.myChart=null;
       this.time=[];
       this.speed=[];
       this.bind();
       this.lineArr=[];
       this.currentPoint=[];
       this.lastPoint=[];
       this.imageChange();
    },
    vehiclePosition : function(){
    	var vehicle_no_color = global.getUrlParam("vehicle_no_color");
    	var alarm_time = global.getUrlParam("alarm_time");
    	var lng = global.getUrlParam("lng");
    	var lat = global.getUrlParam("lat");
    	vehicleCar = vehicle_no_color.split('_');
    	document.title = vehicleCar[0]+ '_' + global.carColor(vehicleCar[1]) + '-车辆位置';
    	
    	$.ajax({
    		type : 'post',
    		url : basePath + "/report/alarmSyn/vehiclePosition.html",
    		data : {"vehicle_no_color" : vehicle_no_color , "alarm_time" : alarm_time,"lng" : lng,"lat":lat},
    		dataType : "JSON",
    		success : function(data) {
            	if(data){
                	mapTool.addAlarmMarker(data.data);
                	mapTool.setCenter(data.data);
            	}
    		}
    	});
    },
    bind : function(){
    	 $("#mTrafficLi").toggle(function(){
    		 vehicleMonitor.trafficLayer = new AMap.TileLayer.Traffic({zIndex:10}); //实时路况图层
    		 vehicleMonitor.trafficLayer.setMap(mapTool.map);
			 $('.t8').addClass("active");
		 },function(){
			 vehicleMonitor.trafficLayer.setMap(null);
			 $('.t8').removeClass("active");
		 });
		 
		 $("#distanceLi").click(function(){
			  mapTool.map.plugin(["AMap.RangingTool"], function() {
			     ruler = new AMap.RangingTool(mapTool.map);
		         AMap.event.addListener(ruler, "end", function(e) {
		            ruler.turnOff();
		            $('.t6').removeClass("active");
		         });
		         ruler.turnOn();
		         $('.t6').addClass("active");
			  });
		 });		
	
		 $("#mSatellite").toggle(function(){
			 $('#mRoadlite').removeClass('dn');
			 $('#mRoadlite').addClass('selected');
			 vehicleMonitor.satelliteLayer = new AMap.TileLayer.Satellite({zIndex:10}); //实时路况图层
    		 vehicleMonitor.satelliteLayer.setMap(mapTool.map);
			 vehicleMonitor.roadNetLayer = new AMap.TileLayer.RoadNet({zIndex:10}); //实例化路网图层
			 vehicleMonitor.roadNetLayer.setMap(mapTool.map);    		 
			 $('.t10').addClass("active");
		 },function(){
			 vehicleMonitor.satelliteLayer.setMap(null);
			 vehicleMonitor.roadNetLayer.setMap(null);
			 $('.t10').removeClass("active");
			 $('#mRoadlite').addClass('dn');
			 $('#mRoadlite').removeClass('selected');
		 });
		$('#mRoadlite').click(function(){
			if($('#mRoadlite').hasClass('selected')){
				 vehicleMonitor.roadNetLayer.setMap(null); 
				 $('#mRoadlite').removeClass('selected');
			}else{				
				 vehicleMonitor.roadNetLayer = new AMap.TileLayer.RoadNet({zIndex:10}); //实例化路网图层
				 vehicleMonitor.roadNetLayer.setMap(mapTool.map); 
				 $('#mRoadlite').addClass('selected');
			}
		});
    },
    imageChange:function(){
    	var flag = true;
    	$("#toolTopDiv #mRoadlite").click(function(){
    		if(flag){
    			$(this).removeClass('spanSelect');
    			$(this).find('.image').css('background-position','0 -434px');
    			flag=false;
    		}else{
    			$(this).addClass('spanSelect');
    			$(this).find('.image').css('background-position','0 -483px');
    			flag=true;
    		}
    	})
    }
};

vehicleMonitor.init();
